package com.lytxmd.boxtest.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lytxmd.boxtest.R;
import com.lytxmd.boxtest.bean.DeviceInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangyinglong on 2017/5/19.
 */
public class VIListAdapter extends BaseAdapter{
    private List<DeviceInfo.ViBean> datas = new ArrayList<>();

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder vh;
        if (convertView == null){

            vh = new ViewHolder();
            convertView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.vi_item,viewGroup,false);
            vh.viDateTv = (TextView) convertView.findViewById(R.id.vi_date);
            vh.lightVTv = (TextView) convertView.findViewById(R.id.light_v_tv);
            vh.lightITv = (TextView) convertView.findViewById(R.id.light_i_tv);
            vh.wordVTv = (TextView) convertView.findViewById(R.id.word_v_tv);
            vh.wordITv = (TextView) convertView.findViewById(R.id.word_i_tv);
            convertView.setTag(vh);
        }else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.viDateTv.setText(datas.get(i).getRecordTime());
        vh.lightVTv.setText(""+datas.get(i).getLightV());
        vh.lightITv.setText(""+datas.get(i).getLightI());
        vh.wordVTv.setText(""+datas.get(i).getWordV());
        vh.wordITv.setText(""+datas.get(i).getWordI());
        return convertView;
    }
    class ViewHolder{
        private TextView viDateTv,lightVTv,lightITv,wordVTv,wordITv;
    }
    public void setData(List<DeviceInfo.ViBean> datas){
        this.datas = datas;
        notifyDataSetChanged();
    }
}
